<#include "../common/header.htm">
<div class="content-wrapper">
	<input type="hidden" id="questionId" value="${questionId}">
	<input type="hidden" id="scriptId" value="${scriptId}">
	<input type="hidden" id="companyId" value="${company.companyId}">
	<input type="hidden" id="page" value="${page}">
	<input type="hidden" id="index" value="${index}">
	<input type="hidden" id="state" value="${state}">
	<input type="hidden" id="keyword" value="${keyword}">
	<input type="hidden" id="from" value="${from}">
	<section class="content-header">
		<ol class="breadcrumb">
			<li><a href="${ctx}/">首页</a></li>
			<#if from??&&from=='未审核'>
				<li class="active"><a href="${ctx}/questionnaire/approvelist">待审核</a></li>
				<li class="active"><a href="${ctx}/questionnaire/loginfo?id=${questionId}&page=${page}&index=${index}&state=${state}&keyword=${keyword}&from=未审核">审核</a></li>
				<#else>
					<li class="active"><a href="${ctx}/questionnaire/approvedlist">已审核</a></li>
					<li class="active"><a href="${ctx}/questionnaire/loginfo?id=${questionId}&page=${page}&index=${index}&state=${state}&keyword=${keyword}&from=已审核">已审核</a></li>
			</#if>
		</ol>
	</section>
	<div class="audited-container">
		<div class="audited-state"></div>
		<div class="big-title">

				<div class="btn-box">
					<span class="btn" onclick="nextOneOrPreviouOne(0)">上一条</span>
					<span class="btn" onclick="nextOneOrPreviouOne(1)">下一条</span>
					<#if dialogState??&&dialogState==1>
						<span class="btn" name="btn" onclick="passed()">通过</span>
						<span class="btn" name="btn" onclick="reject()">驳回</span>
					</#if>
				</div>

		</div>
		<div class="section">

			<ul class="detail-info">
				<li>
					<span class="title">公司：</span>
					<span>${company.companyName!''}</span>
				</li>
				<li>
					<span class="title">话术：</span>
					<span>${title!''}</span>
				</li>
				<li>
					<span class="title">客户经理：</span>
					<span>${company.accountManagerName!''}</span>
				</li>
			</ul>
		</div>
		<#if from??&&from=='未审核'>
			<div class="section">
				<p class="title">敏感词</p>
				<ul class="sensitive-words">
					<#if sensitiveWordsList?? && (sensitiveWordsList?size > 0) >
						<#list sensitiveWordsList as sensitiveWords>
							<li>${sensitiveWords}</li>
						</#list>
					</#if>
				</ul>
			</div>
		</#if>
		<div class="section">
			<p class="title">审核历史</p>
			<ul class="review-history">
				<#list logs as log>
					<#if log.operType?? && log.operType!=3>
						<li class="agree">
							<div class="info">${log.userName!}
								<span class="prompt">
									<#if log.operType?? && log.operType==1>
											提交审核
										<#elseif log.operType?? && log.operType==2>
											取消审核
										<#elseif log.operType?? && log.operType==3>
											驳回
										<#elseif log.operType?? && log.operType==4>
											通过审核
										<#elseif log.operType?? && log.operType==5>
											上线
										<#elseif log.operType?? && log.operType==6>
											下线
										</#if>
								</span>
							</div>
							<p class="time">${log.createTime!}</p>
						</li>
						<#else>
							<li class="refuse">
								<div class="info">${log.userName!}
									<span class="prompt">
									<#if log.operType?? && log.operType==1>
											提交审核
										<#elseif log.operType?? && log.operType==2>
											取消审核
										<#elseif log.operType?? && log.operType==3>
											驳回
										<#elseif log.operType?? && log.operType==4>
											通过审核
										<#elseif log.operType?? && log.operType==5>
											上线
										<#elseif log.operType?? && log.operType==6>
											下线
										</#if>
								</span>
								</div>
								<p class="time">${log.createTime!}</p>
								<p class="time">原因：${log.operReason!}</p>
							</li>
					</#if>
				</#list>
			</ul>
		</div>
		<div class="section">
			<p class="title">审核内容</p>
		</div>
		<div class="section">
			<table class="table table-hover table-bordered table-striped">
				<thead>
				<tr>
					<th style="width:5%;">编号</th>
					<th>AI文本</th>
					<th>录音转文字 <button  class="btn btn-success btn-xs" onclick="videoToText()">转换</button></th>
					<th style="width:5%;">录音</th>
					<th style="width:10%;">修改时间</th>
				</tr>
				</thead>
				<tbody id="myTable">
				<#if dialogList?? && (dialogList?size > 0) >
					<#list dialogList as dialog>
						<tr>
							<td title="${dialog.answer!}">${dialog.shotAnswer!}</td>
							<td title="${dialog.answerText!}">${dialog.shotAnswerText!}</td>
							<td name="videoToText" answer="${dialog.answer!}" isExist="${dialog.isExistVoice!}"></td>
							<td>
								<#if dialog.isExistVoice?? && dialog.isExistVoice=='yes'>
									<a href="javascript:void(0);" onclick="playSound('${dialog.answer!}','${scriptId!}','${company.companyId!}')">试听</a>
									<#else>
										--
								</#if>
							</td>
							<td>${dialog.updateTime!}</td>
						</tr>
					</#list>
					<#else>
						<tr>
							<td colspan="4" align="center">
								无操作日志
							</td>
						</tr>
				</#if>
				</tbody>
			</table>
		</div>
	</div>
</div>

<script type="text/javascript">
    function playSound(answer,scriptId,companyId)
    {
        var src="${ctx}/dialog/listenAudio?fileName="+answer+"&scriptId="+scriptId+"&companyId="+companyId;
        //非IE内核浏览器
        var strAudio = "<audio id='audioPlay' src='"+src+"' hidden='true'>";
        if ( $( "body" ).find( "audio" ).length <= 0 ){
            $( "body" ).append( strAudio );
        }else{
            $("#audioPlay").attr("src",src);
        }

        var audio = $("#audioPlay")[0];
        //浏览器支持 audion
        audio.play();
    }
    var scriptId=$("#scriptId").val();
    var companyId=$("#companyId").val();
    var questionId=$("#questionId").val();
    var from=$("#from").val();

    var page=$("#page").val();
    var index=$("#index").val();
    var state=$("#state").val();
    var keyword=$("#keyword").val();

    var answer_arr=[];
    var flag=0;//驳回使用到的变量

    $(function () {
        $.ajax({
            url:"${ctx}/questionnaire/findOneById?naireId="+questionId,
            success:function(data){
                if(data!=null&&data.dialogState==2){
                    $(".audited-state").addClass("refuse");
                }else if(data!=null&&data.dialogState==3){
                    $(".audited-state").addClass("adopt");
				}
            }
        });
	});


    function videoToText(){
        	var obj=$("table tbody tr td[name='videoToText']");
        	for(var i=0;i<obj.length;i++){
        	    var answer=$(obj[i]).attr("answer");
                var isexist=$(obj[i]).attr("isexist");
                if(isexist=="yes"){
                    answer_arr.push(answer);
                }
			}
			console.log(answer_arr)
			for (var k=0;k<answer_arr.length;k++){
                var url = "${ctx}/questionnaire/videoToText?scriptId="+scriptId+"&answer="+answer_arr[k]+"&companyId="+companyId;
                $.ajax({
                    url:url,
                    success:function(data){
                        if(data!=null){
                            var arr=$("tbody tr td[name='videoToText']");
                            $("tbody tr td[answer='"+data.answer+"']").html(data.result);
						}
                    }
                });
			}
    }
    //审核通过
    function passed(){
        if (flag) {
            bootbox.alert("不能重复操作!");
            return false;
        }
        var url = "${ctx}/questionnaire/updateDialogState";
        var param = {
            "id":questionId,
            "dialogState":3//3代表审核通过
        };
        $.ajax({
            url:url,
            type:'POST',
            data:param,
            dataType:'text',
            async:false,
            success:function(data){
                if(data=="success"){
                    flag = 1;
                    bootbox.alert("操作成功!",function(){
                        $(".audited-state").addClass("adopt");
                        window.location.reload();
                    });
                }else{
                    flag = 0;
                    bootbox.alert("操作失败!");
                }
            }
        });
	}


    //审核驳回
    function reject() {
        if (flag) {
            bootbox.alert("不能重复操作!");
            return false;
        }
        var title = "驳回";
        base.getView({
            url: "${ctx}/questionnaire/rejectForm?id=" + questionId,
            success: function (result) {
                bootbox.dialog({
                    title: title,
                    message: result,
                    size: "large",
                    closeButton: false,
                    buttons: {
                        cancel: {
                            label: "取消",
                            className: "btn btn-secondary",
                            callback: function () {
                            }
                        },
                        sure: {
                            label: "确定",
                            className: "btn btn-primary",
                            callback: function () {
                                if (flag) {
                                    return;
                                }
                                if ($("#rejectForm").valid()) {
                                    $.ajax({
                                        url: "${ctx}/questionnaire/updateDialogState",
                                        type: 'POST',
                                        data: {
                                            "id": questionId,
                                            "dialogState": 2,//2代表驳回
                                            "memo": $("#memo").val()
                                        },
                                        dataType: 'text',
                                        async: false,
                                        success: function (data) {
                                            if (data == "success") {
                                                flag = 1;
                                                $(".audited-state").addClass("refuse");
                                            } else {
                                                flag = 0;
                                            }
                                            window.location.reload();
                                        },
                                        error: function () {
                                            flag = 0;
                                        }
                                    });
                                }
                                return false;
                            }
                        }
                    }
                })
            }
        })
    };

    function nextOneOrPreviouOne(f){
        if(f){//下一条
			if(index>=sessionStorage.sum-1){
                bootbox.alert("这是最后一条");
                return;
			}
            index=parseInt(index)+1;
            window.location.href="${ctx}/questionnaire/loginfo?index="+index+"&page="+page+"&state="+state+"&keyword="+keyword+"&from="+from;
        }else{//上一条
            if(index<=0){
                bootbox.alert("这是第一条");
                return;
            }
            index=parseInt(index)-1;
            window.location.href="${ctx}/questionnaire/loginfo?index="+index+"&page="+page+"&state="+state+"&keyword="+keyword+"&from="+from;
		}
	}
</script>
<#include "../common/footer.htm">